package com.hogan.basiclibrary.base.websocket;


import okhttp3.WebSocket;
import rx.Subscription;
import rx.functions.Action1;

/**
 * Created by chenhu on 2017/10/10.
 * websocket简单用法介绍
 */

public class UserTest {
    Subscription mRxWebsocketSub;
    WebSocket webSocket;

    /**
     * 初始化websocket
     */
    private void init() {
        mRxWebsocketSub = RxWebSocketUtil.getInstance().getWebSocketInfo("url")
                .subscribe(new Action1<WebSocketInfo>() {
                    @Override
                    public void call(WebSocketInfo webSocketInfo) {
                        webSocket = webSocketInfo.getWebSocket();
                    }
                });
    }

    private void sendMessage() {
        //直接发消息
        webSocket.send("messag");
        //发消息
        RxWebSocketUtil.getInstance().asyncSend("url", "message");
    }


}
